// pages/history/history.js
Page({
  data: {
    historyList: [
      {
        id: 1,
        date: '2025-10-14 12:30',
        foodList: ['米饭', '红烧肉', '青菜'],
        totalCalories: 450
      },
      {
        id: 2,
        date: '2025-10-14 08:15',
        foodList: ['鸡蛋', '牛奶', '面包'],
        totalCalories: 320
      },
      {
        id: 3,
        date: '2025-10-13 18:45',
        foodList: ['面条', '鸡蛋'],
        totalCalories: 280
      }
    ]
  },

  onLoad() {
    console.log('历史记录页面加载');
  },

  onShow() {
    // 页面显示时的逻辑
  },

  // 查看历史记录详情
  viewHistoryDetail(e) {
    const id = e.currentTarget.dataset.id;
    wx.showToast({
      title: '查看记录详情功能待开发',
      icon: 'none'
    });
  },

  // 删除历史记录
  deleteHistory(e) {
    const id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '确认删除',
      content: '确定要删除这条记录吗？',
      success: (res) => {
        if (res.confirm) {
          wx.showToast({
            title: '删除成功',
            icon: 'success'
          });
          // 实际项目中这里需要更新数据
        }
      }
    });
  },

  // 底部导航切换
  switchTab(e) {
    const tab = e.currentTarget.dataset.tab;
    
    switch (tab) {
      case 'home':
        wx.redirectTo({
          url: '/pages/index/index'
        });
        break;
      case 'history':
        // 当前页面，无需跳转
        break;
      case 'plan':
        wx.redirectTo({
          url: '/pages/plan/plan'
        });
        break;
      case 'profile':
        wx.redirectTo({
          url: '/pages/profile/profile'
        });
        break;
      default:
        wx.redirectTo({
          url: '/pages/index/index'
        });
    }
  }
})